/**
 * Created by wangfei on 2017/5/25.
 */

$(function(){
	requirejs.config({
    baseUrl: '../../',
    paths:  {
        avalon: 'javascript/avalon.min',
        jquery: 'js/plugins/jquery/jquery-2.1.1.min',
        config: 'javascript/config',
        api: 'javascript/api',
        layer: 'js/plugins/layer1/layer',
        arg: 'javascript/arg'
    },
    shim: {
        api: {
            deps: ['jquery']
        },
        layer: {
            deps: ['jquery']
        }
    }
});

(function(win, dom, requirejs, initVm) {
    var vm;
    requirejs(['avalon', 'jquery', 'config', 'api', 'layer', 'arg'], function() {
        //初始化vm
        vm = initVm(dom);
    });
	})(window, document, requirejs, function(dom) {
		var vm = avalon.define({
			$id: 'container',
			 form: {
				id: '',
				categoryId: '',
				categoryName: '',
				brandId: '',
				brandName: '',
				barcode: '',
				name: '',
				wareDes: '',
				pricePiece: '',
				priceUnit: '',
				unitId: '',
				unitName: '',
				numberPerBox: '',
				netContent: '',
				weightPiece: '',
				saleSiteId: '',
				saleSiteName: '',
				sendProvinceId: '',
				sendProvinceName: '',
				sendCityId: '',
				sendCityName: '',
				numberWholesale: '',
				numberInventory: '',
				imageMain: '',
				productionLicense: '',
				performStandard: '',
				shelfLife: '',
				methodStorage: '',
				methodPacking: '',
				sizePiece: '',
				dateManufacture: '',
				producingArea: '',
				manufacturer: '',
				manufacturerAddress: '',
				description: '',
				wareAttrList: [
					{wareId: '', name: ''}
				],
				wareStockWarn: {
					threshold: '',
					noticeMobile: ''
				}
			},
			galleryThumbs: [],
			supplier: {},
			params: {},
			wareGet: function(wareId) {
				Api.wareGet({id: wareId}, function(resp) {
					if(resp.code == 0) {
						vm.form = resp.data;
						vm.galleryThumbs = vm.form.imageMain.split(",");
					} else {
						layer.msg(resp.msg);
					}
				});
			},
			supplierGet: function() {
				Api.supplierGet(function(resp) {
					if(resp.code == 0) {
						vm.supplier = resp.data;
					} else {
						layer.msg(resp.msg);
					}
				});
			}

		})
		avalon.scan(dom.body);
		vm.params = Arg.parse(location.href);
		if(vm.params.id) {
			vm.wareGet(vm.params.id);
		}
		vm.supplierGet();
		return vm;
	});
});